# cp00.odc
# A model for a change point fixed-effects model with panel data. The error variance is 
# constant across clusters. Fixed effects have been swept out of the regressors
# in the data file oecd0.dat. Initial values are in inits0.dat.
# Bruce Western 5/24/04

# Model 1, constant error variance, data is in oecd0.dat, inits in inits0.dat
model
{
		for(i in 1:N) {
			y[i] ~ dnorm(mu[i], tau)
			mu[i] <- alpha0 + inprod(alpha[],x[i,]) + beta0*J[i] + J[i]*inprod(beta[],x[i,])
			J[i] <- step(yr[i] - cp - 0.5)
			}
		for(i in 1:p) {
			alpha[i] ~ dnorm(0.0, 1.0E-6)
			beta[i] ~ dnorm(0.0, 1.0E-6)
				}
		for(i in 1:T) {
			priort[i] <- punif[i]/sum(punif[])
			}
			alpha0 ~ dnorm(0.0, 1.0E-6)
		  beta0 ~ dnorm(0.0, 1.0E-6)
			cp ~ dcat(priort[])
			tau ~ dgamma(.001, 0.001)
}

# Model 2, heterogeneous error variance, data is in oecd0.dat, inits in inits0.dat
model
{
		for(i in 1:N) {
			y[i] ~ dnorm(mu[i], tau[cc[i]])
			mu[i] <- alpha0 + inprod(alpha[],x[i,]) + beta0*J[i] + J[i]*inprod(beta[],x[i,])
			J[i] <- step(yr[i] - cp - 0.5)
			}
		for(i in 1:p) {
			alpha[i] ~ dnorm(0.0, 1.0E-6)
			beta[i] ~ dnorm(0.0, 1.0E-6)
				}
		for(i in 1:NC) {
			tau[i] ~ dgamma(.001, 0.001)
			}
		for(i in 1:T) {
			priort[i] <- prior[i]/sum(prior[])
			}
			alpha0 ~ dnorm(0.0, 1.0E-6)
			beta0 ~ dnorm(0.0, 1.0E-6)
			cp ~ dcat(priort[])
			gamma0 <- alpha0 + beta0			# Net effects
			gamma[1] <- alpha[1] + beta[1]
			gamma[2] <- alpha[2] + beta[2]
			gamma[3] <- alpha[3] + beta[3]
  		gamma[4] <- alpha[4] + beta[4]
 	 	gamma[5] <- alpha[5] + beta[5]
 	 	gamma[6] <- alpha[6] + beta[6]
	}